package com.xzkydz.all_sensor.activity;

import android.app.FragmentTransaction;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import com.serialport.ComAssistant.MyFunc;
import com.serialport.ComAssistant.SerialHelper;
import com.serialport.bean.ComBean;
import com.xzkydz.all_sensor.MyApp;
import com.xzkydz.all_sensor.allsensor.R;
import com.xzkydz.all_sensor.fragment.AsFragment;
import com.xzkydz.all_sensor.fragment.EmptFragment;
import com.xzkydz.all_sensor.fragment.FsFragment;
import com.xzkydz.all_sensor.fragment.PressFragment;
import com.xzkydz.all_sensor.fragment.RenCheFragment;
import com.xzkydz.all_sensor.fragment.SettingFlowSensorFragment;
import com.xzkydz.all_sensor.fragment.SevenFiveFragment;
import com.xzkydz.all_sensor.fragment.SpeedFragment;
import com.xzkydz.all_sensor.fragment.TimeFragment;
import com.xzkydz.all_sensor.fragment.WeiYiFragment;
import com.xzkydz.all_sensor.fragment.WenDu_Fragment;
import com.xzkydz.all_sensor.fragment.WenShiDuFragment;
import com.xzkydz.all_sensor.fragment.YaliFragment;
import com.xzkydz.all_sensor.socket.Server;

import java.io.IOException;
import java.security.InvalidParameterException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Queue;
import java.util.Random;

import android_serialport_api.SerialPortFinder;

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
    public static Toolbar toolbar;
    private FloatingActionButton fab;
    private TextView showBar;
    private RelativeLayout relativeLayout;
    private boolean changeBackGround = false;
    private boolean AllShow = true;//是否一直在刷新
    SerialControl ComA;
    DispQueueThread DispQueue;
    SerialPortFinder mSerialPortFinder;//串口设备搜索
    int SensorNumber = 0; // 传感器编号
    private EditText mShowInf;   //显示接收信息窗口
    private TextView mShowTvInf;  // 标题
    private Button mClearButton; //清除按钮
    private FrameLayout mSendInfFl;  // 发送信息
    private View line;  //分割条
    private TextView mShowLine; //显示接收数据的条数
    private int dataNum = 0;   //接收的数据条数
    private String resultInf = "";  //刷新的数据信息

    private boolean showGrid = false; //是否可以点击menu
    boolean showStyle = true;  //默认覆盖
    public float radiou = 0.5f; //测速的半径

    public String code; //测速的半径
    public static String PRESS_SENSOR_NUM = "32";
    public static String PRESS_SENSOR_NUM_HEX = "20";
    public String fuhaoString = "+"; //±75 毫伏

    //温度传感器

    //加速度传感器

    public static List<Integer> list_acc = new ArrayList<Integer>();  //用于计算最大加速度和最小加速度

    //水泵传感器
    private String resultInf1 = "";  //温湿度大气压
    private String resultInf2 = "";  //功率箱
    private String resultInf3 = "";  //压力1
    private String resultInf4 = "";  //压力2
    private String resultInf5 = "";  //超声波流量


    //通风机传感器
    String[] fb_number = {"fb1", "fb2", "fb3", "fb4", "fb5", "fb6", "fb7", "fb8", "fb9", "fb10", "fb11", "fb12", "fb13", "fb14", "fb15", "fb16"}; //风杯
    private String tfj_res1 = "";  //温湿度大气压
    private String tfj_res2 = "";  //-6kpa压力
    private String tfj_res3 = "";  //功率1
    private String tfj_res4 = "";  //功率2
    private String tfj_res5 = "";  //差压
    private String tfj_res6 = "";  //风杯

    //架空

    private String jk_res1 = "";  //温湿度大气压
    private String jk_res2 = "";  //速度
    private String jk_res3 = "";  //拉力
    private String jk_res4 = "";  //倾角
    private String jk_res5 = "";  //60Mpa压力

    //空压机

    private String kyj_res1 = "";  //温湿度大气压
    private String kyj_res2 = "";  //功率
    private String kyj_res3 = "";  //1Mpa压力
    private String kyj_res4 = "";  //1Mpa压力
    private String kyj_res5 = "";  //风速
    private String kyj_res6 = "";  //无线温度
    private String kyj_res7 = "";  //无限温度


    //斜井人车

    private String rc_res1 = "";  //温湿度大气压
    private String rc_res2 = "";  //速度
    private String rc_res3 = "";  //拉力
    private String rc_res4 = "";  //倾角
    private String rc_res5 = "加速度：无";  //振动
    private String rc_res6 = "";  //时间

    //皮带机

    private String pdj_res1 = "";  //温湿度大气压
    private String pdj_res2 = "";  //功率
    private String pdj_res3 = "";  //速度
    private String pdj_res4 = "";  //压力60Mpa
    private String pdj_res5 = "";  //位移

    //防坠器

    private String fzq_res1 = "温湿度大气压：无\n";  //温湿度大气压
    private String fzq_res2 = "加速度：无\n";  //振动
    private String fzq_res3 = "激光测距：无\n";  //激光测距
    String[] jigunag = {"0 距离 ：无", "1 距离 ：无", "2 距离 ：无", "3 距离 ：无", "4 距离 ：无", "5 距离 ：无", "6 距离 ：无"}; //激光测距

    //提升机

    private String tsj1 = "温湿度大气压:无\n";  //温湿度大气压
    private String tsj2 = "无线速度：无\n";  //无线速度
    private String tsj3 = "无线拉力：无\n";  //无线拉力
    private String tsj4 = "60Mpa压力：无\n";  //60Mpa压力
    private String tsj5 = "60Mpa压力：无\n";  //60Mpa压力
    private String tsj6 = "无线位移：无\n";  //无线位移
    private String tsj7 = "无线时间：无\n";  //无线时间
    private String tsj8 = "柔性电流钳：无\n";  //柔性电流钳
    private String tsj9 = "电流电压采集：无\n";  //电流电压采集


    private EmptFragment emptFragment;
    private FrameLayout sysFrameLayout;
    private ToggleButton mTogglButton;
    List<Integer> resList = new ArrayList<Integer>();  //  加速度数据集合
    List<Integer> resList2 = new ArrayList<Integer>();  //  加速度数据集合

    List<byte[]> resList_byte = new ArrayList<byte[]>();  //  加速度数据集合
    List<byte[]> resList2_byte = new ArrayList<byte[]>();  //  加速度数据集合
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;
    private ToggleButton mToggleButton2;
    private Spinner sensorChooseSpinner;


    public float fs = 0;  //风速、风杯
    private MyApp myApp;

    private Random random = new Random();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        myApp = new MyApp();

        /*打开服务*/
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                Server server = new Server(myApp);
                server.start();
            }
        });
        thread.start();


        showBar = (TextView) findViewById(R.id.tv_show_bar);
        fab = (FloatingActionButton) findViewById(R.id.fab);
        relativeLayout = (RelativeLayout) findViewById(R.id.Rl_main);

        mShowInf = (EditText) findViewById(R.id.et_show_inf);
        mShowTvInf = (TextView) findViewById(R.id.tv_showInf);
        mClearButton = (Button) findViewById(R.id.btn_clear);
        mSendInfFl = (FrameLayout) findViewById(R.id.fl_send_inf);
        line = (View) findViewById(R.id.view_line);
        mShowLine = (TextView) findViewById(R.id.show_line);
        sysFrameLayout = (FrameLayout) findViewById(R.id.fl_sys);
        mTogglButton = (ToggleButton) findViewById(R.id.toBtn);
        mToggleButton2 = (ToggleButton) findViewById(R.id.allShow);
        sensorChooseSpinner = (Spinner) findViewById(R.id.sp_sensor_choose);

        final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();
        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);


        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                drawer.openDrawer(GravityCompat.START);
            }
        });

        toolbar.setVisibility(View.GONE);
        fab.setVisibility(View.GONE);
        Animation ani = new AlphaAnimation(0f, 1f);
        ani.setDuration(1500);
        ani.setRepeatMode(Animation.REVERSE);
        ani.setRepeatCount(Animation.INFINITE);
        showBar.startAnimation(ani);
        showBar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                drawer.openDrawer(GravityCompat.START);
            }
        });
        //串口控制
        ComA = new SerialControl();
        DispQueue = new DispQueueThread();
        DispQueue.start();
        setControls();


        mClearButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mShowInf.setText("");
                mShowLine.setText((dataNum = 0) + "条");
                Toast.makeText(MainActivity.this, "显示区域已清空  ...", Toast.LENGTH_SHORT).show();
            }
        });
        //压力传感器型号
        sensorChooseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        PRESS_SENSOR_NUM = "32";
                        PRESS_SENSOR_NUM_HEX = "20";
                        Toast.makeText(MainActivity.this, PRESS_SENSOR_NUM_HEX, Toast.LENGTH_SHORT).show();
                        break;
                    case 1:
                        PRESS_SENSOR_NUM = "33";
                        PRESS_SENSOR_NUM_HEX = "21";
                        Toast.makeText(MainActivity.this, PRESS_SENSOR_NUM_HEX, Toast.LENGTH_SHORT).show();
                        break;
                    case 2:
                        PRESS_SENSOR_NUM = "34";
                        PRESS_SENSOR_NUM_HEX = "22";
                        Toast.makeText(MainActivity.this, PRESS_SENSOR_NUM_HEX, Toast.LENGTH_SHORT).show();
                        break;
                    case 3:
                        PRESS_SENSOR_NUM = "35";
                        PRESS_SENSOR_NUM_HEX = "23";
                        Toast.makeText(MainActivity.this, PRESS_SENSOR_NUM_HEX, Toast.LENGTH_SHORT).show();
                        break;
                    default:
                        break;
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });


        //控制显示或者暂停
        mToggleButton2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                AllShow = !AllShow;
            }
        });

        //空白fragment
        emptFragment = new EmptFragment();
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.fl_send_inf, emptFragment).commit();
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    public int sensorNumber() {
        int id = (int) sensorChooseSpinner.getSelectedItemId();
        return id;
    }


    //----------------------------------------------------显示接收数据
    private void DispRecData(ComBean ComRecData) {
        StringBuilder sMsg = new StringBuilder();
        DecimalFormat df2 = new DecimalFormat("####00.00");
        DecimalFormat df3 = new DecimalFormat("####00.000");
        DecimalFormat df4 = new DecimalFormat("####00.0000");
        boolean showLineNum = false;  // 是否显示条数
        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd   HH-mm-ss", Locale.getDefault());
        int LEIXING = ComRecData.bRec[7];
        mTogglButton.setVisibility(View.VISIBLE);

        switch (SensorNumber) {
            case 30: //所有传感器
                if (LEIXING == Integer.parseInt(PRESS_SENSOR_NUM)) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;
                    String jinkouyali = df3.format((float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 1000 + myApp.getAdjust());
                    Log.d("asd", "jinkouyali: " + jinkouyali);
                    Log.d("asd", "myApp.getAdjust(): " + myApp.getAdjust());

                    resultInf = "压力 ： " + jinkouyali + " Kpa";
                }
                break;
            case 1: //-6000Pa ~ 0 Pa
                if (LEIXING == 34) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;
                    float resFloat = (float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 1000;

                    if (6f <= resFloat) {
                        resFloat = resFloat - 0.15f;
                    } else if (5f < resFloat && resFloat < 6f) {
                        resFloat = resFloat - 0.14f;
                    } else if (4f < resFloat && resFloat <= 5f) {
                        resFloat = resFloat - (0.13f + (resFloat - 4f) * 0.012f);
                    } else if (1f < resFloat && resFloat <= 4f) {
                        resFloat = resFloat - (0.056f + (resFloat - 1f) / 3f * 0.073f);
                    } else if (0f < resFloat && resFloat <= 1f) {
                        resFloat = resFloat - (0.024f + (resFloat - 1f) * 0.032f);
                    }
                    if (resFloat >= 2f) {
                        resFloat = resFloat * 1.01f - 0.02f;
                    }

                    resFloat += myApp.getAdjust();
                    String jinkouyali = df3.format(resFloat);
                    resultInf = "压力 ： " + "-" + jinkouyali + " Kpa";
                }

                break;
            case 2: // -0.1 ~ 1 Mpa

                if (LEIXING == 32) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;
                    float jkylFloat = (float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 100;
                    jkylFloat += myApp.getAdjust();


//                    if (jkylFloat>0.8f)  {
//                        jkylFloat = jkylFloat*1.5f/1.52f;
//                    }else if (jkylFloat<0.8f || jkylFloat==0.8f){
//                        jkylFloat = jkylFloat*1.505f/1.52f;
//                    }

                    String jinkouyali = df3.format(jkylFloat);
//                    if ((ComRecData.bRec[13] | 0x00) != 0x00) {
//                        jinkouyali = "- " + jinkouyali;
//                    }
                    resultInf = "              压力 ： " + jinkouyali + " Mpa";
                }

                break;
            case 3://矿用本安型无线电流变送器 +- 75mv
                if (LEIXING == -89) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;
                    float dlbsq = (float) 1.009 * MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) * MyFunc.twobyteToint_(ComRecData.bRec[13], ComRecData.bRec[14]) / 10000;
                    if (dlbsq > 2800) dlbsq = dlbsq - 15;
                    dlbsq += myApp.getAdjust();
                    String dl = df2.format(dlbsq);
                    resultInf = "             电流 ：  " + fuhaoString + " " + dl + " A";
                }

                break;
            case 4: //矿用本安型无线激光测距传感器
                if (LEIXING == -95) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;
                    int a = ComRecData.bRec[10];
                    int b = ComRecData.bRec[11];
                    int c = ComRecData.bRec[12];
                    int d = ComRecData.bRec[13];
                    int e = ComRecData.bRec[14];
                    int f = ComRecData.bRec[15];
                    int g = ComRecData.bRec[16];
                    String aString = MyFunc.asciiToString(a);
                    String bString = MyFunc.asciiToString(b);
                    String cString = MyFunc.asciiToString(c);
                    String dString = MyFunc.asciiToString(d);
                    String eString = MyFunc.asciiToString(e);
                    String fString = MyFunc.asciiToString(f);
                    String gString = MyFunc.asciiToString(g);

                    String resString = aString + bString + cString + dString + eString + fString + gString;
                    float resFloat = Float.parseFloat(resString);
                    if (resFloat <= 4) {
                        resFloat = resFloat - 0.003f;
                    } else if (7 < resFloat && resFloat < 15) {
                        resFloat = resFloat + 0.003f;
                    } else if (resFloat >= 15) {
                        resFloat = resFloat + 0.007f;
                    }

                    resFloat += myApp.getAdjust();
                    resultInf = "             距离 ： " + resFloat + " m";
                }


                break;
            case 5://拉力
                if (LEIXING == 64) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;
                    float res = (float) MyFunc.twobyteToint(ComRecData.bRec[10], ComRecData.bRec[11]);
                    if (0f < res && res < 30f || res > 170f) {
                        res = res + (float) Math.random() * 0.5f + 0.5f;
                    } else if (30f <= res && res <= 170f) {
                        res = res + (float) Math.random() * 0.5f + 1.5f;
                    }

                    String Lali = df2.format(res);
                    res += myApp.getAdjust();
                    resultInf = "              拉力： " + Lali + " KN";
                }
                break;
            case 6://矿用本安型无线倾角传感器

                //首位代表符号位
                if (LEIXING == -94) {
                    if (mTogglButton.isChecked()) {
                        long currentTimeMillis = System.currentTimeMillis();
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTimeInMillis(currentTimeMillis);
                        Date date = new Date(currentTimeMillis);
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss SSS");
                        simpleDateFormat.format(date);
                        code = simpleDateFormat.format(date) + "---" + MyFunc.ByteArrToHex(ComRecData.bRec);
                    }
                    showLineNum = true;
                    String xxString = df2.format((float) MyFunc.twobyteToint(ComRecData.bRec[10], ComRecData.bRec[11]) / 100);
                    String yyString = df2.format((float) MyFunc.twobyteToint(ComRecData.bRec[12], ComRecData.bRec[13]) / 100);
                    String zzString = df2.format((float) MyFunc.twobyteToint(ComRecData.bRec[14], ComRecData.bRec[15]) / 100);


                    resultInf = "        X轴倾角 ： " + xxString + " 度" + "        y轴倾角 ： " + yyString + " 度" + "        z轴倾角 ： " + zzString + " 度";
                }
                break;
            case 7://无线柔性电流传感器

//                在后面再加上个判断
//                大于等于1.2小于1.5 减去0.2
//                大于等于0.9小于1.2 减去0.3
//                小于0.9减去 0.7

                if (LEIXING == -86) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;
                    int dlq = MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]);
                    float dlq_ = (float) dlq / 10 + (float) Math.random() * 0.01f;
                    if (0 < dlq_ && dlq_ < 3) dlq_ = dlq_ - 0.15f;


                    if (1.2f <= dlq_ && dlq_ < 1.5f) {
                        dlq_ = dlq_ - 0.2f;
                    } else if (0.9f <= dlq_ && dlq_ < 1.2f) {
                        dlq_ = dlq_ - 0.3f;
                    } else if (dlq_ < 0.9f) {
                        dlq_ = dlq_ - 0.7f;
                    }

                    dlq_ += myApp.getAdjust();

                    resultInf = "            柔性电流钳：  " + df2.format(dlq_) + "  A";
                }
                break;
            case 8://速度

//                String code = MyFunc.ByteArrToHex(ComRecData.bRec);
//                long currentTimeMillis = System.currentTimeMillis();
//                Calendar calendar = Calendar.getInstance();
//                calendar.setTimeInMillis(currentTimeMillis);
//                Date date = new Date(currentTimeMillis);
//                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss SSS");
//                simpleDateFormat.format(date);
//                resultInf = simpleDateFormat.format(date)+"----"+code+"\n";
//                resultInf ="             频率 ： " + pinlv + " Hz"+"         速度："+sp+"  m/s"

                if (LEIXING == 96) {
                    if (mTogglButton.isChecked()) {
                        long currentTimeMillis = System.currentTimeMillis();
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTimeInMillis(currentTimeMillis);
                        Date date = new Date(currentTimeMillis);
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss SSS");
                        simpleDateFormat.format(date);
                        code = simpleDateFormat.format(date) + "---" + MyFunc.ByteArrToHex(ComRecData.bRec);
                    }
                    showLineNum = true;
                    int aa = MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]);
                    int ab = MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]);
                    int ac = MyFunc.twobyteToint_(ComRecData.bRec[14], ComRecData.bRec[15]);
                    int ad = MyFunc.twobyteToint_(ComRecData.bRec[16], ComRecData.bRec[17]);
                    int ae = MyFunc.twobyteToint_(ComRecData.bRec[18], ComRecData.bRec[19]);
                    int af = MyFunc.twobyteToint_(ComRecData.bRec[20], ComRecData.bRec[21]);
                    int ag = MyFunc.twobyteToint_(ComRecData.bRec[22], ComRecData.bRec[23]);
                    int ah = MyFunc.twobyteToint_(ComRecData.bRec[24], ComRecData.bRec[25]);
                    int ai = MyFunc.twobyteToint_(ComRecData.bRec[26], ComRecData.bRec[27]);
                    int aj = MyFunc.twobyteToint_(ComRecData.bRec[28], ComRecData.bRec[29]);

                    float res = (float) (aa + ab + ac + ad + ae + af + ag + ah + ai + aj) / 60;
                    float speed = 0;
                    if (res > 0) {
                        speed = res * radiou * 2 * 3.1415f;
                    }

                    speed += myApp.getAdjust();

                    String pinlv = df2.format(res);
                    String sp = df3.format(speed);
                    String all = MyFunc.ByteArrToHex(ComRecData.bRec);
                    String tran = aa + "   " + ab + "    " + ac + "     " + ad + "    " + ae + "    " + af + "    " + ag + "   " + ah + "    " + ai + "    " + aj + "    ";
                    resultInf = "             频率 ： " + pinlv + " Hz" + "         速度：" + sp + "  m/s"
                    ;

                    Log.d("ceui", "aa: " + aa);
                    Log.d("ceui", "ab: " + ab);
                    Log.d("ceui", "ac: " + ac);
                    Log.d("ceui", "ad: " + ad);
                    Log.d("ceui", "ae: " + ae);
                    Log.d("ceui", "af: " + af);
                    Log.d("ceui", "ag: " + ag);
                    Log.d("ceui", "ah: " + ah);
                    Log.d("ceui", "ai: " + ai);
                    Log.d("ceui", "aj: " + aj);
                    Log.d("ceui", "res: " + res);
                    Log.d("ceui", "speed: " + speed);
                    Log.d("ceui", "radiou: " + radiou);
                }
                break;
            case 9://无线位移传感器
                if (LEIXING == -90) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;
                    String weiyi2 = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]) / 100 + myApp.getAdjust());
                    resultInf = "              位移 ： " + weiyi2 + " mm";
                }
                break;
            case 10://无线振动 （加速度）
                if (LEIXING == -92 && ComRecData.bRec.length == 94) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;
                    resList_byte.add(ComRecData.bRec);
                    resultInf = MyFunc.ByteArrToHex(ComRecData.bRec) + "\n";

                    String res_ = "解析数据：";
                    for (int j = 0; j < 40; j++) {  // TODO: 2016/8/22   确定i
                        int num = (11 + 2 * j);
                        int res_int = MyFunc.twobyteToint(ComRecData.bRec[num], ComRecData.bRec[num + 1]);
                        list_acc.add(res_int);  //将数据放到List
                        res_ += res_int + "    ";
                    }
                    resultInf = MyFunc.ByteArrToHex(ComRecData.bRec) + "\n" + res_ + "\n";
                }
                if (LEIXING == -92 && ComRecData.bRec.length == 14) {
                    Toast.makeText(MainActivity.this, "接收到回复信号......", Toast.LENGTH_SHORT).show();
                    resultInf = "\n" + "请求ACK:" + "\n" + MyFunc.ByteArrToHex(ComRecData.bRec) + "\n\n";
                }
                if (LEIXING == -92 && ComRecData.bRec.length == 11) {
                    Toast.makeText(MainActivity.this, "接收到回复信号......", Toast.LENGTH_SHORT).show();
                    resultInf = "\n" + "配置ACK:" + "\n" + MyFunc.ByteArrToHex(ComRecData.bRec) + "\n\n";
                }
                break;
            case 11: //超声波流量温度
                //配置超声波流量
                if (LEIXING == -96 && ComRecData.bRec.length == 42) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;  //显示条数
                    float flowNum = (float) MyFunc.byte2float(ComRecData.bRec, 10);  //流量
                    float liusufloat = (float) MyFunc.byte2float(ComRecData.bRec, 14); //流速
                    float xinhaoqingdufloat = (float) MyFunc.HexToInt(MyFunc.Byte2Hex(ComRecData.bRec[32])); //信号强度
                    float guangjingfloat = (float) MyFunc.byte2float(ComRecData.bRec, 18); //管径
                    float inTempfloat = (float) MyFunc.byte2float(ComRecData.bRec, 22) + (float) 0.6; //进口温度
                    float outTempfloat = (float) MyFunc.byte2float(ComRecData.bRec, 26) + (float) 0.5; //出口温度
                    int anzhuang = (int) ComRecData.bRec[34];//安装距离

                    String anzhaungjuli = null;
                    switch (anzhuang) {
                        case 0:
                            anzhaungjuli = df2.format((float) MyFunc.byteArrayToInt(ComRecData.bRec, 35));
                            break;
                        case 1:
                            anzhaungjuli = df2.format((float) MyFunc.byteArrayToInt(ComRecData.bRec, 35) / 10);
                            break;
                        case 2:
                            anzhaungjuli = df2.format((float) MyFunc.byteArrayToInt(ComRecData.bRec, 35) / 100);
                            break;
                        case 3:
                            anzhaungjuli = df2.format((float) MyFunc.byteArrayToInt(ComRecData.bRec, 35) / 1000);
                            break;
                        case 4:
                            anzhaungjuli = df2.format((float) MyFunc.byteArrayToInt(ComRecData.bRec, 35) / 10000);
                            break;
                        case 5:
                            anzhaungjuli = df2.format((float) MyFunc.byteArrayToInt(ComRecData.bRec, 35) / 100000);
                            break;
                        default:
                            break;
                    }
                    if ((int) (ComRecData.bRec[33] & 0x00) == 1) {
                        anzhaungjuli = "- " + anzhaungjuli;
                    }

                    String xhqdString = df2.format(xinhaoqingdufloat); //信号强度
                    String azjlString = anzhaungjuli;  //安装距离
                    String ltsdString = df2.format(liusufloat); //流速
                    String llString = df2.format(flowNum); //流量
                    String gjString = df2.format(guangjingfloat); //管径
                    String inTempString = df2.format(inTempfloat);  //进口温度
                    String outTempString = df2.format(outTempfloat);//出口温度

                    String inf1 = "    信号强度：" + xhqdString + "     安装距离：" + anzhaungjuli + "\n";
                    String inf2 = "    流体速度：" + ltsdString + " m/s" + "         流量：" + llString + " m³/h" + "    管径：" + gjString + "\n";
                    String inf3 = "    进口温度：" + inTempString + " ℃" + "     出口温度：" + outTempString + " ℃" + "\n\n\n\n\n\n";
                    resultInf = inf1 + inf2 + inf3;
                }

                break;
            case 12: //无线温度

                if (LEIXING == 17) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;
                    String wendu1 = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 100 + myApp.getAdjust());
                    resultInf = "              温度 ： " + wendu1 + "℃";
                }
                break;
            case 13://无线差压 0——2kpa
                if (LEIXING == 48) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;
                    String chaya2 = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 100 + myApp.getAdjust()); //解析出来是整数，除1000是得到小数点后三位
                    resultInf = "              差压 ： " + chaya2;
                }
                break;
            case 14: //无线风杯
                if (LEIXING == 80) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;
                    float pinlv = (float) MyFunc.fourByte2int(ComRecData.bRec, 10) / 1000;
                    float fengsu = (float) MyFunc.fourByte2int(ComRecData.bRec, 14) / 100;

//                    y = 0.0002x2 + 0.1053x + 0.1779
                    fengsu = 0.0002F * fengsu * fengsu + 0.1053f * fengsu + 0.1779f + myApp.getAdjust();

                    if (myApp.isIsShowGuding()){
                        fengsu = myApp.getGudingData() + (random.nextFloat() -0.5f) *2 * myApp.getJingduDat();
                    }

//                    resultInf = "              风速 ： " + df2.format(fengsu) + "m/s" + "\n" + "              频率 ： " + df3.format(pinlv) + "HZ";
                    resultInf = "              风速 ： " + df2.format(fengsu) + "m/s";
                }
                break;
            case 15: //无线风速
                if (LEIXING == -91) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                    showLineNum = true;
                    String fengbei2 = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]) / 100 + myApp.getAdjust());
                    resultInf = "              风速 ： " + fengbei2 + "m/s";
                }
                break;
            case 16://无线时间
                if (LEIXING == 81 && ComRecData.bRec.length == 17) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);

                    showLineNum = true;
                    float miao1 = (float) MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]);
                    float hoamaio1 = (float) MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]) * 0.1f / 1000;
                    float res = hoamaio1 + miao1 + myApp.getAdjust();
                    resultInf = "              时间 ： " + df4.format(res) + "" + " s";
                }
                break;
            case 17: //温湿度大气压
                if (LEIXING == 16) {
                    if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);

                    if (ComRecData.bRec[9] == 1) {
                        String wenduString = df2.format((float) MyFunc.twoByte2int(ComRecData.bRec, 19) / 100); //温度
                        if ((int) (ComRecData.bRec[18] | 0x00) == 1)
                            wenduString = "- " + wenduString;  //判断是否是零下温度
                        String daqiyasString = df2.format((float) MyFunc.fourByte2int(ComRecData.bRec, 21) / 100);  //大气压
                        String shiduString = df2.format((float) MyFunc.byte2float(ComRecData.bRec, 14));  // 湿度
                        resultInf = "        温度： " + wenduString + " ℃" + "        大气压： " + daqiyasString + " hPa" + "        湿度： " + shiduString + " %RH";
                        showLineNum = true;
                    }

                    if (ComRecData.bRec[9] == 2 || ComRecData.bRec[9] == 3) {
                        resultInf = "\n\n\n" + "ACK： " + MyFunc.ByteArrToHex(ComRecData.bRec) + "\n\n\n";
                        showLineNum = true;
                    }
                }
                break;

            case 18://旧版拉力
                String code = MyFunc.ByteArrToHex(ComRecData.bRec);
                long currentTimeMillis = System.currentTimeMillis();
                Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis(currentTimeMillis);
                Date date = new Date(currentTimeMillis);
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss SSS");
                simpleDateFormat.format(date);
                resultInf = simpleDateFormat.format(date) + "----" + code + "\n";
                break;

            case 21: //通风机
                mTogglButton.setVisibility(View.GONE);
                switch (LEIXING) {
                    case 80:  //风杯  //// TODO: 2016/8/23   风杯
                        showLineNum = true;
                        int number = (int) ComRecData.bRec[8] - 1;  //风杯编号
                        String fengbei2 = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]) / 100);
                        fb_number[number] = "风杯" + number + ": " + fengbei2 + "m/s";
                        tfj_res6 = fb_number[0] + "  " + fb_number[1] + "\n" + fb_number[2] + "  " + fb_number[3] + "\n" + fb_number[4] + "  " + fb_number[5] + "\n" +
                                fb_number[6] + "  " + fb_number[7] + "\n" + fb_number[8] + "  " + fb_number[9] + "\n" + fb_number[10] + "  " + fb_number[11] + "\n" +
                                fb_number[12] + "  " + fb_number[13] + "\n" + fb_number[14] + "  " + fb_number[15] + "\n\n";
                        resultInf = tfj_res1 + tfj_res2 + tfj_res3 + tfj_res4 + tfj_res5 + tfj_res6;  //六类传感器
                        break;
                    case 16:  //(温湿度大气压)
                        showLineNum = true;
                        String wenduString = df2.format((float) MyFunc.twoByte2int(ComRecData.bRec, 19) / 100); //温度
                        if ((int) (ComRecData.bRec[18] | 0x00) == 1)
                            wenduString = "- " + wenduString;  //判断是否是零下温度
                        String daqiyasString = df2.format((float) MyFunc.fourByte2int(ComRecData.bRec, 21) / 100);  //大气压
                        String shiduString = df2.format((float) MyFunc.byte2float(ComRecData.bRec, 14));  // 湿度
                        tfj_res1 = "温度： " + wenduString + " ℃" + "        大气压： " + daqiyasString + " hPa" + "        湿度： " + shiduString + " %RH" + "\n\n";
                        resultInf = tfj_res1 + tfj_res2 + tfj_res3 + tfj_res4 + tfj_res5 + tfj_res6;
                        break;

                    case -128:  //功率箱    // TODO: 2016/8/23   功率箱传感器代码？
                        showLineNum = true;
                        int num = (int) ComRecData.bRec[8];
                        float Ua = ((float) MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]) / 10000 * 500);
                        float Ub = ((float) MyFunc.twobyteToint_(ComRecData.bRec[14], ComRecData.bRec[15]) / 10000 * 500);
                        float Uc = ((float) MyFunc.twobyteToint_(ComRecData.bRec[18], ComRecData.bRec[19]) / 10000 * 500);
                        float Ia = ((float) MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]) / 10000 * 500);
                        float Ib = ((float) MyFunc.twobyteToint_(ComRecData.bRec[16], ComRecData.bRec[17]) / 10000 * 500);
                        float Ic = ((float) MyFunc.twobyteToint_(ComRecData.bRec[20], ComRecData.bRec[21]) / 10000 * 500);
                        float u0 = (Ua + Ub + Uc) / 3;
                        float i0 = (Ia + Ib + Ic) / 3;
                        float P = ((float) MyFunc.twobyteToint_Sp(ComRecData.bRec[22], ComRecData.bRec[23]) / 10000000 * 3 * 500 * 500);  //总有功功率
                        float Q = ((float) MyFunc.twobyteToint_Sp(ComRecData.bRec[24], ComRecData.bRec[25]) / 10000000 * 3 * 500 * 500);  //总无功功率
                        float Cos = ((float) MyFunc.twobyteToint_Sp(ComRecData.bRec[26], ComRecData.bRec[27]) / 10000);  //功率因数
                        if (num == 1)
                            tfj_res3 = "电压1 ： " + df2.format(u0) + " V" + "\n" + "电流1 ： " + df2.format(i0) + " A" + "\n" + "有功功率1：" + df2.format(P) + "W\n" + "无功功率1：" + df3.format(Q) + "Var\n" + "功率因数1：" + df3.format(Cos) + "\n\n";
                        else
                            tfj_res4 = "电压2 ： " + df2.format(u0) + " V" + "\n" + "电流2 ： " + df2.format(i0) + " A" + "\n" + "有功功率2：" + df2.format(P) + "W\n" + "无功功率2：" + df3.format(Q) + "Var\n" + "功率因数2：" + df3.format(Cos) + "\n\n";
                        resultInf = tfj_res1 + tfj_res2 + tfj_res3 + tfj_res4 + tfj_res5 + tfj_res6;
                        break;

                    case 34://压力 -6kpa
                        showLineNum = true;
                        String yl2 = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 1000);
                        tfj_res2 = "压力 ： " + "—" + yl2 + " Mpa" + "\n\n";
                        resultInf = tfj_res1 + tfj_res2 + tfj_res3 + tfj_res4 + tfj_res5 + tfj_res6;
                        break;
                    case 48: //差压
                        showLineNum = true;
                        String chaya2 = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 100);
                        tfj_res5 = "              差压 ： " + chaya2 + "\n\n";
                        resultInf = tfj_res1 + tfj_res2 + tfj_res3 + tfj_res4 + tfj_res5 + tfj_res6;
                        break;
                    default:
                        break;
                }
                break;
            case 22: //架空
                mTogglButton.setVisibility(View.GONE);
                switch (LEIXING) {
                    case 16:  //(温湿度大气压)
                        showLineNum = true;
                        String wenduString = df2.format((float) MyFunc.twoByte2int(ComRecData.bRec, 19) / 100); //温度
                        if ((int) (ComRecData.bRec[18] | 0x00) == 1)
                            wenduString = "- " + wenduString;  //判断是否是零下温度
                        String daqiyasString = df2.format((float) MyFunc.fourByte2int(ComRecData.bRec, 21) / 100);  //大气压
                        String shiduString = df2.format((float) MyFunc.byte2float(ComRecData.bRec, 14));  // 湿度
                        jk_res1 = "温度： " + wenduString + " ℃" + "        大气压： " + daqiyasString + " hPa" + "        湿度： " + shiduString + " %RH" + "\n\n";
                        resultInf = jk_res1 + jk_res2 + jk_res3 + jk_res4 + jk_res5;
                        break;

                    case 96:  //无线速度
                        showLineNum = true;
                        int aa = MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]);
                        int ab = MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]);
                        int ac = MyFunc.twobyteToint_(ComRecData.bRec[14], ComRecData.bRec[15]);
                        int ad = MyFunc.twobyteToint_(ComRecData.bRec[16], ComRecData.bRec[16]);
                        int ae = MyFunc.twobyteToint_(ComRecData.bRec[18], ComRecData.bRec[19]);
                        int af = MyFunc.twobyteToint_(ComRecData.bRec[20], ComRecData.bRec[21]);
                        int ag = MyFunc.twobyteToint_(ComRecData.bRec[22], ComRecData.bRec[23]);
                        int ah = MyFunc.twobyteToint_(ComRecData.bRec[24], ComRecData.bRec[25]);
                        int ai = MyFunc.twobyteToint_(ComRecData.bRec[26], ComRecData.bRec[27]);
                        int aj = MyFunc.twobyteToint_(ComRecData.bRec[28], ComRecData.bRec[29]);

                        float res = (float) (aa + ab + ac + ad + ae + af + ag + ah + ai + aj) / 60;
                        float speed = 0;
                        if (res > 0) {
                            speed = 1 / res * radiou * 2 * 3.1415f;
                        }
                        String pinlv = df2.format(res);
                        String sp = df3.format(speed);
                        jk_res2 = "             频率 ： " + pinlv + " Hz" + "         速度：" + sp + "  m/s" + "\n\n";
                        resultInf = jk_res1 + jk_res2 + jk_res3 + jk_res4 + jk_res5;
                        break;

                    case 64: //无线拉力
                        showLineNum = true;
                        String Lali = df2.format((float) MyFunc.twobyteToint(ComRecData.bRec[10], ComRecData.bRec[11]));
                        jk_res3 = "              拉力： " + Lali + " N" + "\n\n";
                        resultInf = jk_res1 + jk_res2 + jk_res3 + jk_res4 + jk_res5;
                        break;
                    case -94: //倾角
                        showLineNum = true;
                        String xxString = df2.format((float) MyFunc.twobyteToint(ComRecData.bRec[10], ComRecData.bRec[11]) / 100);
                        String yyString = df2.format((float) MyFunc.twobyteToint(ComRecData.bRec[12], ComRecData.bRec[13]) / 100);
                        String zzString = df2.format((float) MyFunc.twobyteToint(ComRecData.bRec[14], ComRecData.bRec[15]) / 100);
                        jk_res4 = "        X轴倾角 ： " + xxString + " 度" + "        y轴倾角 ： " + yyString + " 度" + "        z轴倾角 ： " + zzString + " 度" + "\n\n";
                        resultInf = jk_res1 + jk_res2 + jk_res3 + jk_res4 + jk_res5;
                        break;
                    case 33: //压力 0~60Mpa
                        showLineNum = true;
                        String jinkouyali = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 1000);
                        jk_res5 = "压力 ： " + jinkouyali + " Mpa" + "\n\n";
                        resultInf = jk_res1 + jk_res2 + jk_res3 + jk_res4 + jk_res5;
                        break;
                    default:
                        break;
                }


                break;
            case 23: //空压机
                mTogglButton.setVisibility(View.GONE);
                switch (LEIXING) {
                    case 16:  //(温湿度大气压)
                        showLineNum = true;
                        String wenduString = df2.format((float) MyFunc.twoByte2int(ComRecData.bRec, 19) / 100); //温度
                        if ((int) (ComRecData.bRec[18] | 0x00) == 1)
                            wenduString = "- " + wenduString;  //判断是否是零下温度
                        String daqiyasString = df2.format((float) MyFunc.fourByte2int(ComRecData.bRec, 21) / 100);  //大气压
                        String shiduString = df2.format((float) MyFunc.byte2float(ComRecData.bRec, 14));  // 湿度
                        kyj_res1 = "温度： " + wenduString + " ℃" + "        大气压： " + daqiyasString + " hPa" + "        湿度： " + shiduString + " %RH" + "\n\n";
                        resultInf = kyj_res1 + kyj_res2 + kyj_res3 + kyj_res4 + kyj_res5 + kyj_res6 + kyj_res7;
                        break;
                    case -128:  //功率箱    // TODO: 2016/8/23   功率箱传感器代码？
                        showLineNum = true;
                        float Ua = ((float) MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]) / 10000 * 500);
                        float Ub = ((float) MyFunc.twobyteToint_(ComRecData.bRec[14], ComRecData.bRec[15]) / 10000 * 500);
                        float Uc = ((float) MyFunc.twobyteToint_(ComRecData.bRec[18], ComRecData.bRec[19]) / 10000 * 500);
                        float Ia = ((float) MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]) / 10000 * 500);
                        float Ib = ((float) MyFunc.twobyteToint_(ComRecData.bRec[16], ComRecData.bRec[17]) / 10000 * 500);
                        float Ic = ((float) MyFunc.twobyteToint_(ComRecData.bRec[20], ComRecData.bRec[21]) / 10000 * 500);
                        float u0 = (Ua + Ub + Uc) / 3;
                        float i0 = (Ia + Ib + Ic) / 3;
                        float P = ((float) MyFunc.twobyteToint_Sp(ComRecData.bRec[22], ComRecData.bRec[23]) / 10000000 * 3 * 500 * 500);  //总有功功率
                        float Q = ((float) MyFunc.twobyteToint_Sp(ComRecData.bRec[24], ComRecData.bRec[25]) / 10000000 * 3 * 500 * 500);  //总无功功率
                        float Cos = ((float) MyFunc.twobyteToint_Sp(ComRecData.bRec[26], ComRecData.bRec[27]) / 10000);  //功率因数
                        kyj_res2 = "电压 ： " + df2.format(u0) + " V" + "\n" + "电流 ： " + df2.format(i0) + " A" + "\n" + "有功功率：" + df2.format(P) + "W\n" + "无功功率：" + df3.format(Q) + "Var\n" + "功率因数：" + df3.format(Cos) + "\n\n";
                        resultInf = kyj_res1 + kyj_res2 + kyj_res3 + kyj_res4 + kyj_res5 + kyj_res6 + kyj_res7;
                        break;
                    case 35: //1Mpa
                        showLineNum = true;
                        int num = (int) ComRecData.bRec[8];
                        String jinkouyali = df3.format((float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 1000);
                        if ((ComRecData.bRec[13] | 0x00) != 0x00) {
                            jinkouyali = "- " + jinkouyali;
                        }
                        if (num == 1)
                            kyj_res3 = "一级排气压力 ： " + jinkouyali + " Mpa" + "\n";
                        else
                            kyj_res4 = "二级排气压力 ： " + jinkouyali + " Mpa" + "\n\n";
                        resultInf = kyj_res1 + kyj_res2 + kyj_res3 + kyj_res4 + kyj_res5 + kyj_res6 + kyj_res7;
                        break;
                    case -91: //风速
                        showLineNum = true;
                        String chaya2 = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]) / 100); //解析出来是整数，除1000是得到小数点后三位
                        kyj_res5 = "风速 ： " + chaya2 + "m/s" + "\n\n";
                        resultInf = kyj_res1 + kyj_res2 + kyj_res3 + kyj_res4 + kyj_res5 + kyj_res6 + kyj_res7;
                        break;
                    case 17://温度
                        showLineNum = true;
                        int nums = ComRecData.bRec[8];
                        String wendu1 = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 100);
                        if (nums == 1) kyj_res6 = "一级排气温度 ： " + wendu1 + "℃" + "\n";
                        else kyj_res7 = "二级排气温度 ： " + wendu1 + "℃" + "\n\n";
                        resultInf = kyj_res1 + kyj_res2 + kyj_res3 + kyj_res4 + kyj_res5 + kyj_res6 + kyj_res7;
                        break;
                    default:
                        break;

                }


                break;
            case 24: //人车
                mTogglButton.setVisibility(View.GONE);
                switch (LEIXING) {
                    case 16:  //(温湿度大气压)
                        showLineNum = true;
                        String wenduString = df2.format((float) MyFunc.twoByte2int(ComRecData.bRec, 19) / 100); //温度
                        if ((int) (ComRecData.bRec[18] | 0x00) == 1)
                            wenduString = "- " + wenduString;  //判断是否是零下温度
                        String daqiyasString = df2.format((float) MyFunc.fourByte2int(ComRecData.bRec, 21) / 100);  //大气压
                        String shiduString = df2.format((float) MyFunc.byte2float(ComRecData.bRec, 14));  // 湿度
                        rc_res1 = "温度： " + wenduString + " ℃" + "        大气压： " + daqiyasString + " hPa" + "        湿度： " + shiduString + " %RH" + "\n\n";
                        resultInf = rc_res1 + rc_res2 + rc_res3 + rc_res4 + rc_res5 + rc_res6;
                        break;
                    case 96:  //无线速度
                        showLineNum = true;

                        int aa = MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]);
                        int ab = MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]);
                        int ac = MyFunc.twobyteToint_(ComRecData.bRec[14], ComRecData.bRec[15]);
                        int ad = MyFunc.twobyteToint_(ComRecData.bRec[16], ComRecData.bRec[16]);
                        int ae = MyFunc.twobyteToint_(ComRecData.bRec[18], ComRecData.bRec[19]);
                        int af = MyFunc.twobyteToint_(ComRecData.bRec[20], ComRecData.bRec[21]);
                        int ag = MyFunc.twobyteToint_(ComRecData.bRec[22], ComRecData.bRec[23]);
                        int ah = MyFunc.twobyteToint_(ComRecData.bRec[24], ComRecData.bRec[25]);
                        int ai = MyFunc.twobyteToint_(ComRecData.bRec[26], ComRecData.bRec[27]);
                        int aj = MyFunc.twobyteToint_(ComRecData.bRec[28], ComRecData.bRec[29]);

                        float res = (float) (aa + ab + ac + ad + ae + af + ag + ah + ai + aj) / 60;
                        float speed = 0;
                        if (res > 0) {
                            speed = 1 / res * radiou * 2 * 3.1415f;
                        }
                        String pinlv = df2.format(res); //解析出来是整数，除1000是得到小数点后三位
                        String sp = df3.format(speed); //解析出来是整数，除1000是得到小数点后三位
                        rc_res2 = "             频率 ： " + pinlv + " Hz" + "         速度：" + sp + "  m/s" + "\n\n";
                        resultInf = rc_res1 + rc_res2 + rc_res3 + rc_res4 + rc_res5 + rc_res6;
                        break;
                    case 64: //无线拉力
                        showLineNum = true;
                        String Lali = df2.format((float) MyFunc.twobyteToint(ComRecData.bRec[10], ComRecData.bRec[11]));
                        rc_res3 = "              拉力： " + Lali + " N" + "\n\n";
                        resultInf = rc_res1 + rc_res2 + rc_res3 + rc_res4 + rc_res5 + rc_res6;
                    case -94: //倾角
                        showLineNum = true;
                        String xxString = df2.format((float) MyFunc.twobyteToint(ComRecData.bRec[10], ComRecData.bRec[11]) / 100);
                        String yyString = df2.format((float) MyFunc.twobyteToint(ComRecData.bRec[12], ComRecData.bRec[13]) / 100);
                        String zzString = df2.format((float) MyFunc.twobyteToint(ComRecData.bRec[14], ComRecData.bRec[15]) / 100);
                        rc_res4 = "        X轴倾角 ： " + xxString + " 度" + "        y轴倾角 ： " + yyString + " 度" + "        z轴倾角 ： " + zzString + " 度" + "\n\n";
                        resultInf = rc_res1 + rc_res2 + rc_res3 + rc_res4 + rc_res5 + rc_res6;
                        break;
                    case -92://加速度

                        if (LEIXING == -92 && ComRecData.bRec.length == 94) {
                            if (mTogglButton.isChecked())
                                code = MyFunc.ByteArrToHex(ComRecData.bRec);
                            showLineNum = true;
                            resList_byte.add(ComRecData.bRec);
                            resultInf = MyFunc.ByteArrToHex(ComRecData.bRec) + "\n";

                            String res_ = "解析数据：";
                            for (int j = 0; j < 40; j++) {  // TODO: 2016/8/22   确定i
                                int num = (11 + 2 * j);
                                int res_int = MyFunc.twobyteToint(ComRecData.bRec[num], ComRecData.bRec[num + 1]);
                                list_acc.add(res_int);  //将数据放到List
                                res_ += res_int + "    ";
                            }
                            resultInf = MyFunc.ByteArrToHex(ComRecData.bRec) + "\n" + res_ + "\n";
                        }

                        if (LEIXING == -92 && ComRecData.bRec.length == 14) {
                            Toast.makeText(MainActivity.this, "接收到回复信号......", Toast.LENGTH_SHORT).show();
                            resultInf = "\n" + "ACK:" + "\n" + MyFunc.ByteArrToHex(ComRecData.bRec) + "\n\n";
                        }
                        break;
                    case 81: // 时间
                        showLineNum = true;
                        if (ComRecData.bRec.length == 17) {
                            if (mTogglButton.isChecked())
                                code = MyFunc.ByteArrToHex(ComRecData.bRec);
                            showLineNum = true;
                            float miao1 = (float) MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]);
                            float hoamaio1 = (float) MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]) * 0.1f / 1000;
                            float resas = hoamaio1 + miao1;
                            rc_res6 = "时间 ： " + df4.format(resas) + "" + " s" + "\n\n";
                            resultInf = rc_res1 + rc_res2 + rc_res3 + rc_res4 + rc_res5 + rc_res6;
                        }
                        break;
                    default:
                        break;
                }
                break;
            case 25:  //水泵
                mTogglButton.setVisibility(View.GONE);
                switch (LEIXING) {
                    case 16:  //(温湿度大气压)
                        showLineNum = true;
                        String wenduString = df2.format((float) MyFunc.twoByte2int(ComRecData.bRec, 19) / 100); //温度
                        if ((int) (ComRecData.bRec[18] | 0x00) == 1)
                            wenduString = "- " + wenduString;  //判断是否是零下温度
                        String daqiyasString = df2.format((float) MyFunc.fourByte2int(ComRecData.bRec, 21) / 100);  //大气压
                        String shiduString = df2.format((float) MyFunc.byte2float(ComRecData.bRec, 14));  // 湿度
                        resultInf1 = "温度： " + wenduString + " ℃" + "        大气压： " + daqiyasString + " hPa" + "        湿度： " + shiduString + " %RH" + "\n\n";
                        resultInf = resultInf1 + resultInf2 + resultInf3 + resultInf4 + resultInf5;
                        break;
                    case -128:  //功率箱    // TODO: 2016/8/23   功率箱传感器代码？
                        showLineNum = true;
                        float Ua = ((float) MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]) / 10000 * 500);
                        float Ub = ((float) MyFunc.twobyteToint_(ComRecData.bRec[14], ComRecData.bRec[15]) / 10000 * 500);
                        float Uc = ((float) MyFunc.twobyteToint_(ComRecData.bRec[18], ComRecData.bRec[19]) / 10000 * 500);
                        float Ia = ((float) MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]) / 10000 * 500);
                        float Ib = ((float) MyFunc.twobyteToint_(ComRecData.bRec[16], ComRecData.bRec[17]) / 10000 * 500);
                        float Ic = ((float) MyFunc.twobyteToint_(ComRecData.bRec[20], ComRecData.bRec[21]) / 10000 * 500);
                        float u0 = (Ua + Ub + Uc) / 3;
                        float i0 = (Ia + Ib + Ic) / 3;
                        float P = ((float) MyFunc.twobyteToint_Sp(ComRecData.bRec[22], ComRecData.bRec[23]) / 10000000 * 3 * 500 * 500);  //总有功功率
                        float Q = ((float) MyFunc.twobyteToint_Sp(ComRecData.bRec[24], ComRecData.bRec[25]) / 10000000 * 3 * 500 * 500);  //总无功功率
                        float Cos = ((float) MyFunc.twobyteToint_Sp(ComRecData.bRec[26], ComRecData.bRec[27]) / 10000);  //功率因数
                        resultInf2 = "电压 ： " + df2.format(u0) + " V" + "\n" + "电流 ： " + df2.format(i0) + " A" + "\n" + "有功功率：" + df2.format(P) + "W\n" + "无功功率：" + df3.format(Q) + "Var\n" + "功率因数：" + df3.format(Cos) + "\n\n";
                        resultInf = resultInf1 + resultInf2 + resultInf3 + resultInf4 + resultInf5;
                        break;
                    case 32:  //0~60Mpa
                        showLineNum = true;
                        String jinkouyali = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 1000); //解析出来是整数，除1000是得到小数点后三位
                        resultInf4 = "出口压力 ： " + jinkouyali + " Mpa" + "\n\r";
                        resultInf = resultInf1 + resultInf2 + resultInf3 + resultInf4 + resultInf5;
                        break;
                    case 35: //-1~1Mpa
                        showLineNum = true;
                        String jinkouyali2 = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 1000); //解析出来是整数，除1000是得到小数点后三位
                        if ((ComRecData.bRec[13] & 0x00) != 0x00) {
                            jinkouyali2 = "- " + jinkouyali2;
                        }
                        resultInf3 = "进口压力 ： " + jinkouyali2 + " Mpa" + "\n\n";
                        resultInf = resultInf1 + resultInf2 + resultInf3 + resultInf4 + resultInf5;
                        break;

                    case -96:
                        if (ComRecData.bRec.length == 42) {
                            showLineNum = true;  //显示条数
                            float flowNum = (float) MyFunc.byte2float(ComRecData.bRec, 10);  //流量
                            float liusufloat = (float) MyFunc.byte2float(ComRecData.bRec, 14); //流速
                            float xinhaoqingdufloat = (float) MyFunc.HexToInt(MyFunc.Byte2Hex(ComRecData.bRec[32])); //信号强度
                            float guangjingfloat = (float) MyFunc.byte2float(ComRecData.bRec, 18); //管径
                            float inTempfloat = (float) MyFunc.byte2float(ComRecData.bRec, 22); //进口温度
                            float outTempfloat = (float) MyFunc.byte2float(ComRecData.bRec, 26); //出口温度
                            int anzhuang = (int) ComRecData.bRec[34];//安装距离

                            String anzhaungjuli = null;
                            switch (anzhuang) {
                                case 0:
                                    anzhaungjuli = df2.format((float) MyFunc.byteArrayToInt(ComRecData.bRec, 35));
                                    break;
                                case 1:
                                    anzhaungjuli = df2.format((float) MyFunc.byteArrayToInt(ComRecData.bRec, 35) / 10);
                                    break;
                                case 2:
                                    anzhaungjuli = df2.format((float) MyFunc.byteArrayToInt(ComRecData.bRec, 35) / 100);
                                    break;
                                case 3:
                                    anzhaungjuli = df2.format((float) MyFunc.byteArrayToInt(ComRecData.bRec, 35) / 1000);
                                    break;
                                case 4:
                                    anzhaungjuli = df2.format((float) MyFunc.byteArrayToInt(ComRecData.bRec, 35) / 10000);
                                    break;
                                case 5:
                                    anzhaungjuli = df2.format((float) MyFunc.byteArrayToInt(ComRecData.bRec, 35) / 100000);
                                    break;
                                default:
                                    break;
                            }
                            if ((int) (ComRecData.bRec[33] & 0x00) == 1) {
                                anzhaungjuli = "- " + anzhaungjuli;
                            }

                            String xhqdString = df2.format(xinhaoqingdufloat); //信号强度
                            String ltsdString = df2.format(liusufloat); //流速
                            String llString = df2.format(flowNum); //流量
                            String gjString = df2.format(guangjingfloat); //管径
                            String inTempString = df2.format(inTempfloat);  //进口温度
                            String outTempString = df2.format(outTempfloat);//出口温度

                            String inf1 = "信号强度：" + xhqdString + "     安装距离：" + anzhaungjuli + "\n\n";
                            String inf2 = "流体速度：" + ltsdString + " m/s" + "         流量：" + llString + "m³/h" + "    管径：" + gjString + " mm" + "\n\n";
                            String inf3 = "进口温度：" + inTempString + " ℃" + "     出口温度：" + outTempString + " ℃" + "\n\n";
                            resultInf5 = inf1 + inf2 + inf3;
                            Log.v("res", "resultInf5" + resultInf5);
                            resultInf = resultInf1 + resultInf2 + resultInf3 + resultInf4 + resultInf5;
                        }

                        break;
                    default:
                        break;

                }
                break;
            case 26://皮带机
                mTogglButton.setVisibility(View.GONE);
                switch (LEIXING) {
                    case 16:  //(温湿度大气压)
                        showLineNum = true;
                        String wenduString = df2.format((float) MyFunc.twoByte2int(ComRecData.bRec, 19) / 100); //温度
                        if ((int) (ComRecData.bRec[18] | 0x00) == 1)
                            wenduString = "- " + wenduString;  //判断是否是零下温度
                        String daqiyasString = df2.format((float) MyFunc.fourByte2int(ComRecData.bRec, 21) / 100);  //大气压
                        String shiduString = df2.format((float) MyFunc.byte2float(ComRecData.bRec, 14));  // 湿度
                        pdj_res1 = "温度： " + wenduString + " ℃" + "        大气压： " + daqiyasString + " hPa" + "        湿度： " + shiduString + " %RH" + "\n\n";
                        resultInf = pdj_res1 + pdj_res2 + pdj_res3 + pdj_res4 + pdj_res5;
                        break;
                    case -128: //功率箱
                        showLineNum = true;
                        float Ua = ((float) MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]) / 10000 * 500);
                        float Ub = ((float) MyFunc.twobyteToint_(ComRecData.bRec[14], ComRecData.bRec[15]) / 10000 * 500);
                        float Uc = ((float) MyFunc.twobyteToint_(ComRecData.bRec[18], ComRecData.bRec[19]) / 10000 * 500);
                        float Ia = ((float) MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]) / 10000 * 500);
                        float Ib = ((float) MyFunc.twobyteToint_(ComRecData.bRec[16], ComRecData.bRec[17]) / 10000 * 500);
                        float Ic = ((float) MyFunc.twobyteToint_(ComRecData.bRec[20], ComRecData.bRec[21]) / 10000 * 500);
                        float u0 = (Ua + Ub + Uc) / 3;
                        float i0 = (Ia + Ib + Ic) / 3;
                        float P = ((float) MyFunc.twobyteToint_Sp(ComRecData.bRec[22], ComRecData.bRec[23]) / 10000000 * 3 * 500 * 500);  //总有功功率
                        float Q = ((float) MyFunc.twobyteToint_Sp(ComRecData.bRec[24], ComRecData.bRec[25]) / 10000000 * 3 * 500 * 500);  //总无功功率
                        float Cos = ((float) MyFunc.twobyteToint_Sp(ComRecData.bRec[26], ComRecData.bRec[27]) / 10000);  //功率因数
                        pdj_res2 = "电压 ： " + df2.format(u0) + " V" + "\n" + "电流 ： " + df2.format(i0) + " A" + "\n" + "有功功率：" + df2.format(P) + "W\n" + "无功功率：" + df3.format(Q) + "Var\n" + "功率因数：" + df3.format(Cos) + "\n\n";
                        resultInf = pdj_res1 + pdj_res2 + pdj_res3 + pdj_res4 + pdj_res5;
                        break;
                    case 96:  //无线速度
                        showLineNum = true;
                        int aa = MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]);
                        int ab = MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]);
                        int ac = MyFunc.twobyteToint_(ComRecData.bRec[14], ComRecData.bRec[15]);
                        int ad = MyFunc.twobyteToint_(ComRecData.bRec[16], ComRecData.bRec[16]);
                        int ae = MyFunc.twobyteToint_(ComRecData.bRec[18], ComRecData.bRec[19]);
                        int af = MyFunc.twobyteToint_(ComRecData.bRec[20], ComRecData.bRec[21]);
                        int ag = MyFunc.twobyteToint_(ComRecData.bRec[22], ComRecData.bRec[23]);
                        int ah = MyFunc.twobyteToint_(ComRecData.bRec[24], ComRecData.bRec[25]);
                        int ai = MyFunc.twobyteToint_(ComRecData.bRec[26], ComRecData.bRec[27]);
                        int aj = MyFunc.twobyteToint_(ComRecData.bRec[28], ComRecData.bRec[29]);

                        float res = (float) (aa + ab + ac + ad + ae + af + ag + ah + ai + aj) / 60;
                        float speed = 0;
                        if (res > 0) {
                            speed = 1 / res * radiou * 2 * 3.1415f;
                        }
                        String pinlv = df2.format(res);
                        String sp = df3.format(speed);
                        pdj_res3 = "             频率 ： " + pinlv + " Hz" + "         速度：" + sp + "  m/s" + "\n\n";
                        resultInf = pdj_res1 + pdj_res2 + pdj_res3 + pdj_res4 + pdj_res5;
                        break;
                    case 33: //压力 60Mpa
                        showLineNum = true;
                        String jinkouyali = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 1000); //解析出来是整数，除1000是得到小数点后三位
                        pdj_res4 = "压力 ： " + jinkouyali + " Mpa" + "\n\n";
                        resultInf = pdj_res1 + pdj_res2 + pdj_res3 + pdj_res4 + pdj_res5;
                        break;
                    case -90://位移
                        showLineNum = true;
                        String weiyi2 = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]) / 100);
                        pdj_res5 = "位移 ： " + weiyi2 + " mm" + "\n\n";
                        resultInf = pdj_res1 + pdj_res2 + pdj_res3 + pdj_res4 + pdj_res5;
                        break;
                    default:
                        break;
                }
                break;
            case 29: //提升机
                mTogglButton.setVisibility(View.GONE);

                Log.d("addd", LEIXING + "提升机");
                switch (LEIXING) {
                    case 16:  //(温湿度大气压)
                        showLineNum = true;
                        String wenduString = df2.format((float) MyFunc.twoByte2int(ComRecData.bRec, 19) / 100); //温度
                        if ((int) (ComRecData.bRec[18] | 0x00) == 1)
                            wenduString = "- " + wenduString;  //判断是否是零下温度
                        String daqiyasString = df2.format((float) MyFunc.fourByte2int(ComRecData.bRec, 21) / 100);  //大气压
                        String shiduString = df2.format((float) MyFunc.byte2float(ComRecData.bRec, 14));  // 湿度
                        tsj1 = "温度： " + wenduString + " ℃" + "        大气压： " + daqiyasString + " hPa" + "        湿度： " + shiduString + " %RH" + "\n\n";
                        resultInf = tsj1 + tsj2 + tsj3 + tsj4 + tsj5 + tsj6 + tsj7 + tsj8 + tsj9;
                        break;

                    case 96:  //无线速度
                        showLineNum = true;

                        int aa = MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]);
                        int ab = MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]);
                        int ac = MyFunc.twobyteToint_(ComRecData.bRec[14], ComRecData.bRec[15]);
                        int ad = MyFunc.twobyteToint_(ComRecData.bRec[16], ComRecData.bRec[16]);
                        int ae = MyFunc.twobyteToint_(ComRecData.bRec[18], ComRecData.bRec[19]);
                        int af = MyFunc.twobyteToint_(ComRecData.bRec[20], ComRecData.bRec[21]);
                        int ag = MyFunc.twobyteToint_(ComRecData.bRec[22], ComRecData.bRec[23]);
                        int ah = MyFunc.twobyteToint_(ComRecData.bRec[24], ComRecData.bRec[25]);
                        int ai = MyFunc.twobyteToint_(ComRecData.bRec[26], ComRecData.bRec[27]);
                        int aj = MyFunc.twobyteToint_(ComRecData.bRec[28], ComRecData.bRec[29]);

                        float res = (float) (aa + ab + ac + ad + ae + af + ag + ah + ai + aj) / 60;
                        float speed = 0;
                        if (res > 0) {
                            speed = 1 / res * radiou * 2 * 3.1415f;
                        }
                        String pinlv = df2.format(res);
                        String sp = df3.format(speed);
                        tsj2 = "             频率 ： " + pinlv + " Hz" + "         速度：" + sp + "  m/s" + "\n\n";
                        resultInf = tsj1 + tsj2 + tsj3 + tsj4 + tsj5 + tsj6 + tsj7 + tsj8 + tsj9;
                        break;

                    case 64: //无线拉力
                        showLineNum = true;
                        String Lali = df2.format((float) MyFunc.twobyteToint(ComRecData.bRec[10], ComRecData.bRec[11]));
                        tsj3 = "              拉力： " + Lali + " N" + "\n\n";
                        resultInf = tsj1 + tsj2 + tsj3 + tsj4 + tsj5 + tsj6 + tsj7 + tsj8 + tsj9;
                        break;
                    case 33: //压力 60Mpa
                        showLineNum = true;
                        int num_tsj = (int) ComRecData.bRec[8];
                        String jinkouyali = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) / 1000); //解析出来是整数，除1000是得到小数点后三位
                        if (num_tsj == 1) tsj4 = "压力1 ： " + jinkouyali + " Mpa" + "\n\n";
                        else tsj5 = "压力2 ： " + jinkouyali + " Mpa" + "\n\n";
                        resultInf = tsj1 + tsj2 + tsj3 + tsj4 + tsj5 + tsj6 + tsj7 + tsj8 + tsj9;
                        break;

                    case -90://位移
                        showLineNum = true;
                        String weiyi2 = df2.format((float) MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]) / 100);
                        tsj6 = "位移 ： " + weiyi2 + " mm" + "\n\n";
                        resultInf = tsj1 + tsj2 + tsj3 + tsj4 + tsj5 + tsj6 + tsj7 + tsj8 + tsj9;
                    case 81: // 时间
                        showLineNum = true;
                        if (ComRecData.bRec.length == 17) {
                            float miao1 = (float) MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]);
                            float hoamaio1 = (float) MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]) * 0.1f / 1000;
                            float resas = hoamaio1 + miao1;
                            tsj7 = "时间 ： " + df4.format(resas) + "" + " s" + "\n\n";
                            resultInf = tsj1 + tsj2 + tsj3 + tsj4 + tsj5 + tsj6 + tsj7 + tsj8 + tsj9;
                        }
                        break;
                    case -89://电流采集器
                        showLineNum = true;
                        String dl = df2.format((float) 1.009 * MyFunc.twobyteToint_(ComRecData.bRec[11], ComRecData.bRec[12]) * MyFunc.twobyteToint_(ComRecData.bRec[13], ComRecData.bRec[14]) / 10000);
                        tsj9 = "             +- 75mv 电流 ： " + fuhaoString + " " + dl + " A" + "\n\n";
                        resultInf = tsj1 + tsj2 + tsj3 + tsj4 + tsj5 + tsj6 + tsj7 + tsj8 + tsj9;
                        break;

                    case -86://柔性电流钳

                        if (mTogglButton.isChecked()) code = MyFunc.ByteArrToHex(ComRecData.bRec);
                        showLineNum = true;
                        int a1 = MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]);
                        float b1 = (float) a1 / 100;
                        tsj8 = "柔性电流钳 ： " + b1 + " A" + "\n\n";
                        resultInf = tsj1 + tsj2 + tsj3 + tsj4 + tsj5 + tsj6 + tsj7 + tsj8 + tsj9;
                        break;

                    case -87://电压电流采集器
                        showLineNum = true;
                        //协议写错了，电压与电流写反了
                        int U1 = MyFunc.twobyteToint_(ComRecData.bRec[10], ComRecData.bRec[11]);
                        int U2 = MyFunc.twobyteToint_(ComRecData.bRec[12], ComRecData.bRec[13]);
                        int U3 = MyFunc.twobyteToint_(ComRecData.bRec[14], ComRecData.bRec[15]);
                        int U4 = MyFunc.twobyteToint_(ComRecData.bRec[16], ComRecData.bRec[17]);
                        int U5 = MyFunc.twobyteToint_(ComRecData.bRec[18], ComRecData.bRec[19]);
                        float U = (float) (U1 + U2 + U3 + U4 + U5) / 3f;

                        int I1 = MyFunc.twobyteToint_(ComRecData.bRec[20], ComRecData.bRec[21]);
                        int I2 = MyFunc.twobyteToint_(ComRecData.bRec[22], ComRecData.bRec[23]);
                        int I3 = MyFunc.twobyteToint_(ComRecData.bRec[24], ComRecData.bRec[25]);
                        int I4 = MyFunc.twobyteToint_(ComRecData.bRec[26], ComRecData.bRec[27]);
                        int I5 = MyFunc.twobyteToint_(ComRecData.bRec[28], ComRecData.bRec[29]);
                        float I = (float) (I1 + I2 + I3 + I4 + I5) / 25f;

                        tsj9 = "电压电流采集器       " + "电压：" + df2.format(I) + " V" + "       " + "电流：" + df2.format(U) + " mA";
                        resultInf = tsj1 + tsj2 + tsj3 + tsj4 + tsj5 + tsj6 + tsj7 + tsj8 + tsj9;
                        break;
                    default:
                        break;
                }
                break;
            case 28: //防坠器
                mTogglButton.setVisibility(View.GONE);
                Log.d("addd", LEIXING + "防坠器");
                switch (LEIXING) {
                    case 16:  //(温湿度大气压)
                        showLineNum = true;
                        String wenduString = df2.format((float) MyFunc.twoByte2int(ComRecData.bRec, 19) / 100); //温度
                        if ((int) (ComRecData.bRec[18] | 0x00) == 1)
                            wenduString = "- " + wenduString;  //判断是否是零下温度
                        String daqiyasString = df2.format((float) MyFunc.fourByte2int(ComRecData.bRec, 21) / 100);  //大气压
                        String shiduString = df2.format((float) MyFunc.byte2float(ComRecData.bRec, 14));  // 湿度
                        fzq_res1 = "温度： " + wenduString + " ℃" + "        大气压： " + daqiyasString + " hPa" + "        湿度： " + shiduString + " %RH" + "\n\n";
                        resultInf = fzq_res1 + fzq_res2 + fzq_res3;
                        break;
                    case -92://加速度
                        if (LEIXING == -92 && ComRecData.bRec.length == 94) {
                            if (mTogglButton.isChecked())
                                code = MyFunc.ByteArrToHex(ComRecData.bRec);
                            showLineNum = true;
                            resList_byte.add(ComRecData.bRec);
                            resultInf = MyFunc.ByteArrToHex(ComRecData.bRec) + "\n";

                            String res_ = "解析数据：";
                            for (int j = 0; j < 40; j++) {  // TODO: 2016/8/22   确定i
                                int num = (11 + 2 * j);
                                int res_int = MyFunc.twobyteToint(ComRecData.bRec[num], ComRecData.bRec[num + 1]);
                                list_acc.add(res_int);  //将数据放到List
                                res_ += res_int + "    ";
                            }
                            resultInf = MyFunc.ByteArrToHex(ComRecData.bRec) + "\n" + res_ + "\n";
                        }

                        if (LEIXING == -92 && ComRecData.bRec.length == 14) {
                            Toast.makeText(MainActivity.this, "接收到回复信号......", Toast.LENGTH_SHORT).show();
                            resultInf = "\n" + "ACK:" + "\n" + MyFunc.ByteArrToHex(ComRecData.bRec) + "\n\n";
                        }
                        break;
                    case -95:  //激光测距
                        showLineNum = true;
                        int number = (int) ComRecData.bRec[8] - 1;
                        int a = ComRecData.bRec[10];
                        int b = ComRecData.bRec[11];
                        int c = ComRecData.bRec[12];
                        int d = ComRecData.bRec[13];
                        int e = ComRecData.bRec[14];
                        int f = ComRecData.bRec[15];
                        String aString = MyFunc.asciiToString(a);
                        String bString = MyFunc.asciiToString(b);
                        String cString = MyFunc.asciiToString(c);
                        String dString = MyFunc.asciiToString(d);
                        String eString = MyFunc.asciiToString(e);
                        String fString = MyFunc.asciiToString(f);
                        jigunag[number] = number + " 距离 ： " + aString + bString + cString + dString + eString + fString + " m";
                        fzq_res3 = jigunag[0] + "\n" + jigunag[1] + "\n" + jigunag[2] + "\n" + jigunag[3] + "\n" + jigunag[4] + "\n" + jigunag[5] + "\n" +
                                jigunag[6] + "\n";

                        resultInf = fzq_res1 + fzq_res2 + fzq_res3;
                        break;
                    default:
                        break;
                }
                break;
            default:
                break;
        }

        if (showLineNum) {
            // TODO: 2016/8/25 设置是否积累刷新
            if (showStyle) mShowInf.setText("");
            if (mTogglButton.isChecked()) {
                sMsg.append(code);
                sMsg.append("\r\n");
            }
            sMsg.append("\r\n");
            sMsg.append(resultInf);
            sMsg.append("\r\n");
            sMsg.append(" —————————————————————————————————————————————");
            sMsg.append("\r\n");

            if (AllShow) {
                mShowInf.append(sMsg);
                mShowLine.setText((dataNum += 1) + "条");
            }
        }

        //水泵下发指令
        if (SensorNumber == 11) {
            new Handler().postDelayed(new Runnable() {
                public void run() {
                    sendPortData("4B590701050001A00104A7");
                }
            }, 1500);
        }
    }


    //计算最大/最小加速度
    public void getMaxAndMin() {
        if (list_acc.size() > 0) {
            int max = Collections.max(list_acc);
            int min = Collections.min(list_acc);
            StringBuilder sMsg = new StringBuilder();
            sMsg.append("     最大加速度： " + (float) max / 100 + "m/s2" + "\n" + "    最小加速度：" + (float) min / 100 + "m/s2" + "\n\n");
            switch (SensorNumber) {
                case 24:
                    rc_res5 = "最大加速度： " + (float) max / 100 + "m/s2" + "\n" + "最小加速度：" + (float) min / 100 + "m/s2" + "\n\n";
                    break;
                case 28:
                    fzq_res2 = "最大加速度： " + (float) max / 100 + "m/s2" + "\n" + "最小加速度：" + (float) min / 100 + "m/s2" + "\n\n";
            }
            mShowInf.append(sMsg);
        }
        list_acc.clear();

    }


    //activity  销毁的时候关闭串口
    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        CloseComPort(ComA);
    }


    //----------------------------------------------------刷新显示线程
    private class DispQueueThread extends Thread {
        private Queue<ComBean> QueueList = new LinkedList<ComBean>();

        @Override
        public void run() {
            super.run();
            while (!isInterrupted()) {
//                Log.d("ceshi","线程运行");
                final ComBean ComData;
                while ((ComData = QueueList.poll()) != null) {
                    runOnUiThread(new Runnable() {
                        public void run() {

                            DispRecData(ComData);
                        }
                    });
                    try {
                        Thread.sleep(100);//显示性能高的话，可以把此数值调小。
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                }
            }
        }

        public synchronized void AddQueue(ComBean ComData) {
            QueueList.add(ComData);
        }
    }


    // ----------------------------------------------------设置串口
    private void setControls() {
        mSerialPortFinder = new SerialPortFinder();
        String[] entryValues = mSerialPortFinder.getAllDevicesPath(); // 获取所有的串口
        for (int i = 0; i < entryValues.length; i++) {
            System.out.println(entryValues[i]);
        }
        ComA.setPort(entryValues[6]);

        ComA.setBaudRate("9600");
        OpenComPort(ComA);
    }

    //----------------------------------------------------串口控制类
    private class SerialControl extends SerialHelper {

        public SerialControl() {
        }

        protected void onDataReceived(ComBean ComRecData) {
            // TODO Auto-generated method stub
            DispQueue.AddQueue(ComRecData); //线程定时刷新显示(推荐)
        }
    }

    //----------------------------------------------------串口发送
    public void sendPortData(String sOut) {
        if (ComA != null && ComA.isOpen()) {
            ComA.sendHex(sOut);
        }
    }

    //----------------------------------------------------关闭串口
    private void CloseComPort(SerialHelper ComPort) {
        if (ComPort != null) {
            ComPort.stopSend();
            ComPort.close();
        }
    }

    //----------------------------------------------------打开串口
    private void OpenComPort(SerialHelper ComPort) {
        try {
            ComPort.open();
        } catch (SecurityException e) {
            ShowMessage("打开串口失败:没有串口读/写权限!");
        } catch (IOException e) {
            ShowMessage("打开串口失败:未知错误!");
        } catch (InvalidParameterException e) {
            ShowMessage("打开串口失败:参数错误!");
        }
    }

    //
    public void ShowInf(String sMsg) {
        mShowInf.setText("");
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(sMsg);
        mShowInf.append(stringBuilder);

    }

    //------------------------------------------显示消息
    private void ShowMessage(String sMsg) {
        Toast.makeText(this, sMsg, Toast.LENGTH_SHORT).show();
    }


    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        //noinspection SimplifiableIfStatement
        if (showGrid) {
            if (id == R.id.action_settings) {
                LayoutInflater inflater = getLayoutInflater();
                View layout = inflater.inflate(R.layout.alterdilog_detail, null);
                new AlertDialog.Builder(this).setView(layout).show();
                return true;
            }
            if (id == R.id.action_settings2) {
                showStyle = !showStyle;
                if (showStyle) {
                    Toast.makeText(MainActivity.this, "覆盖显示模式", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(MainActivity.this, "累积显示模式", Toast.LENGTH_SHORT).show();
                }
                return true;
            }

            if (id == R.id.action_ip) {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setIcon(R.mipmap.ic_launcher);
                builder.setTitle("本机IP地址");
                builder.setMessage(myApp.getIpStr());
                builder.create().show();
            }
        } else {
            Toast.makeText(MainActivity.this, "请先选择传感器 ...", Toast.LENGTH_SHORT).show();
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        myApp.setAdjust(0.0f);
        // Handle navigation view item clicks here.
        int id = item.getItemId();
        showGrid = true;  //可以显示menu
        SensorNumber = 0;
        resultInf = "";
        //清空显示窗口
        mShowInf.setText("");
        mShowLine.setText((dataNum = 0) + "条");
        sysFrameLayout.setVisibility(View.GONE);
        sensorChooseSpinner.setVisibility(View.GONE);

        if (!changeBackGround) {
            changeBackGround = !changeBackGround;
            relativeLayout.setBackgroundResource(R.drawable.bg_);
            toolbar.setVisibility(View.VISIBLE);
//            fab.setVisibility(View.VISIBLE);
            showBar.clearAnimation();
            showBar.setVisibility(View.GONE);
            mShowInf.setVisibility(View.VISIBLE);
            mShowLine.setVisibility(View.VISIBLE);
            mShowTvInf.setVisibility(View.VISIBLE);
            mSendInfFl.setVisibility(View.VISIBLE);
            line.setVisibility(View.VISIBLE);
            mTogglButton.setVisibility(View.VISIBLE);
            mClearButton.setVisibility(View.VISIBLE);
        }

//所有数据复位
        //水泵传感器
        resultInf1 = "";  //温湿度大气压
        resultInf2 = "";  //功率箱
        resultInf3 = "";  //压力1
        resultInf4 = "";  //压力2
        resultInf5 = "";  //超声波流量
        //通风机传感器
        tfj_res1 = "";  //温湿度大气压
        tfj_res2 = "";  //-6kpa压力
        tfj_res3 = "";  //功率1
        tfj_res4 = "";  //功率2
        tfj_res5 = "";  //差压
        tfj_res6 = "";  //风杯
        //架空
        jk_res1 = "";  //温湿度大气压
        jk_res2 = "";  //速度
        jk_res3 = "";  //拉力
        jk_res4 = "";  //倾角
        jk_res5 = "";  //60Mpa压力
        //空压机
        kyj_res1 = "";  //温湿度大气压
        kyj_res2 = "";  //功率
        kyj_res3 = "";  //1Mpa压力
        kyj_res4 = "";  //1Mpa压力
        kyj_res5 = "";  //风速
        kyj_res6 = "";  //无线温度
        kyj_res7 = "";  //无限温度
        //斜井人车
        rc_res1 = "";  //温湿度大气压
        rc_res2 = "";  //速度
        rc_res3 = "";  //拉力
        rc_res4 = "";  //倾角
        rc_res5 = "加速度：无";  //振动
        rc_res6 = "";  //时间
        //皮带机
        pdj_res1 = "";  //温湿度大气压
        pdj_res2 = "";  //功率
        pdj_res3 = "";  //速度
        pdj_res4 = "";  //压力60Mpa
        pdj_res5 = "";  //位移
        //防坠器
        fzq_res1 = "温湿度大气压：无\n";  //温湿度大气压
        fzq_res2 = "加速度：无\n";  //振动
        fzq_res3 = "激光测距：无\n";  //激光测距

        //提升机

        tsj1 = "温湿度大气压:无\n";  //温湿度大气压
        tsj2 = "无线速度：无\n";  //无线速度
        tsj3 = "无线拉力：无\n";  //无线拉力
        tsj4 = "60Mpa压力：无\n";  //60Mpa压力
        tsj5 = "60Mpa压力：无\n";  //60Mpa压力
        tsj6 = "无线位移：无\n";  //无线位移
        tsj7 = "无线时间：无\n";  //无线时间
        tsj8 = "柔性电流钳：无\n";  //柔性电流钳
        tsj9 = "电流电压采集：无\n";  //电流电压采集
        if (id == R.id.nav_1) {
            toolbar.setTitle("矿用本安型无线压力传感器(-6000Pa ~ 0 Pa)");
            showMsg("矿用本安型无线压力传感器(-6000Pa ~ 0 Pa)");
            SensorNumber = 1;
            showEmptFragment();
        } else if (id == R.id.nav_0) {
            toolbar.setTitle("压力传感器");
            showMsg("矿用本安型无线压力传感器");
            SensorNumber = 30;
            sensorChooseSpinner.setVisibility(View.VISIBLE);
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new YaliFragment()).commit();
        } else if (id == R.id.nav_2) {
            toolbar.setTitle("矿用本安型无线压力传感器(-0.1 ~ 1Mpa)");
            showMsg("矿用本安型无线压力传感器");
            SensorNumber = 2;
            showEmptFragment();
        } else if (id == R.id.nav_3) {
            toolbar.setTitle("矿用本安型无线电流变送器 ± 75mv");
            showMsg("矿用本安型无线电流变送器");
            SensorNumber = 3;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new SevenFiveFragment()).commit();
        } else if (id == R.id.nav_4) {
            toolbar.setTitle("矿用本安型无线激光测距传感器");
            showMsg("矿用本安型无线激光测距传感器");
            SensorNumber = 4;
            showEmptFragment();
        } else if (id == R.id.nav_5) {
            toolbar.setTitle("矿用本安型无线拉力传感器");
            showMsg("矿用本安型无线拉力传感器");
            SensorNumber = 5;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new PressFragment()).commit();

        } else if (id == R.id.nav_6) {
            toolbar.setTitle("矿用本安型无线倾角传感器");
            showMsg("矿用本安型无线倾角传感器");
            SensorNumber = 6;
            showEmptFragment();
        } else if (id == R.id.nav_7) {
            toolbar.setTitle("矿用本安型无线柔性电流传感器");
            showMsg("矿用本安型无线柔性电流传感器");
            SensorNumber = 7;
            showEmptFragment();
        } else if (id == R.id.nav_8) {
            toolbar.setTitle("矿用本安型无线速度传感器");
            showMsg("矿用本安型无线速度传感器");
            SensorNumber = 8;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new SpeedFragment()).commit();
        } else if (id == R.id.nav_9) {
            toolbar.setTitle("矿用本安型无线位移传感器");
            showMsg("矿用本安型无线位移传感器");
            SensorNumber = 9;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new WeiYiFragment()).commit();

        } else if (id == R.id.nav_10) {
            toolbar.setTitle("矿用本安型无线振动传感器");
            showMsg("矿用本安型无线振动传感器");
            SensorNumber = 10;
            showEmptFragment();
            sysFrameLayout.setVisibility(View.GONE);
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new AsFragment()).commit();

        } else if (id == R.id.nav_11) {
            toolbar.setTitle("矿用本安型无线超声波流量温度传感器");
            showMsg("矿用本安型无线超声波流量温度传感器");
            SensorNumber = 11;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new SettingFlowSensorFragment()).commit();

        } else if (id == R.id.nav_12) {
            toolbar.setTitle("矿用本安型无线温度传感器");
            showMsg("矿用本安型无线温度传感器");
            SensorNumber = 12;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new WenDu_Fragment()).commit();
        } else if (id == R.id.nav_13) {
            toolbar.setTitle("矿用本安型无线差压传感器");
            showMsg("矿用本安型无线差压传感器");
            SensorNumber = 13;
            showEmptFragment();
        } else if (id == R.id.nav_14) {
            toolbar.setTitle("矿用本安型无线风杯传感器");
            showMsg("矿用本安型无线风杯传感器");
            SensorNumber = 14;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new FsFragment()).commit();
        } else if (id == R.id.nav_15) {
            toolbar.setTitle("矿用本安型无线风速传感器");
            showMsg("矿用本安型无线风速传感器");
            SensorNumber = 15;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new FsFragment()).commit();
        } else if (id == R.id.nav_16) {
            toolbar.setTitle("矿用本安型无线时间测试传感器");
            showMsg("矿用本安型无线时间测试传感器");
            SensorNumber = 16;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new TimeFragment()).commit();
        } else if (id == R.id.nav_17) {
            toolbar.setTitle("矿用本安型温湿度大气压测试传感器");
            showMsg("矿用本安型温湿度大气压测试传感器");
            SensorNumber = 17;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
//            fragmentTransaction.replace(R.id.fl_send_inf, new WenShiDuFragment()).commit();

            fragmentTransaction.replace(R.id.fl_send_inf, new WenShiDuFragment()).commit();
        } else if (id == R.id.nav_sys_1) {
            toolbar.setTitle("矿用通风机综合测试仪");
            showMsg("矿用通风机综合测试仪");
            showEmptFragment();
            SensorNumber = 21;
        } else if (id == R.id.nav_sys_2) {
            toolbar.setTitle("矿用架空乘人装置检测仪");
            showMsg("矿用架空乘人装置检测仪");
            SensorNumber = 22;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new SpeedFragment()).commit();
        } else if (id == R.id.nav_sys_3) {
            toolbar.setTitle("矿用空压机综合参数测试仪");
            showMsg("矿用空压机综合参数测试仪");
            SensorNumber = 23;
            showEmptFragment();
        } else if (id == R.id.nav_sys_4) {
            toolbar.setTitle("矿用人车综合测试仪");
            showMsg("矿用人车综合测试仪");
            SensorNumber = 24;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new RenCheFragment()).commit();
        } else if (id == R.id.nav_sys_5) {
            toolbar.setTitle("矿用水泵综合测试仪");
            showMsg("矿用水泵综合测试仪");
            SensorNumber = 25;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new SettingFlowSensorFragment()).commit();
        } else if (id == R.id.nav_sys_6) {
            toolbar.setTitle("矿用皮带机综合测试仪");
            showMsg("矿用皮带机综合测试仪");
            SensorNumber = 26;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new SpeedFragment()).commit();
        } else if (id == R.id.nav_sys_7) {
            toolbar.setTitle("矿用提升机性能检测仪");
            showMsg("矿用提升机性能检测仪");
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new TimeFragment()).commit();
            SensorNumber = 29;
        } else if (id == R.id.nav_sys_8) {
            toolbar.setTitle("矿用防坠器综合测试仪");
            showMsg("矿用防坠器综合测试仪");
            SensorNumber = 28;
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fl_send_inf, new AsFragment()).commit();
        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

    private void showEmptFragment() {
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        if (emptFragment != null) {
            fragmentTransaction.replace(R.id.fl_send_inf, emptFragment).commit();
        } else {
            fragmentTransaction.replace(R.id.fl_send_inf, new EmptFragment()).commit();
        }

    }

    private void showMsg(String string) {
        Toast.makeText(MainActivity.this, string, Toast.LENGTH_SHORT).show();
    }

    //屏蔽home
    @Override
    public void onAttachedToWindow() {
        try {
            int version = Build.VERSION.SDK_INT;
            if (version >= 15) {
                this.getWindow().setFlags(0x80000000, 0x80000000);
            } else {
                this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
            }
            super.onAttachedToWindow();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        System.out.println("Page01 -->onKeyDown: keyCode: " + keyCode);
        if (KeyEvent.KEYCODE_HOME == keyCode) {
            System.out.println("HOME has been pressed yet ...");
            // android.os.Process.killProcess(android.os.Process.myPid());
            Toast.makeText(getApplicationContext(), "HOME 键已被禁用...",
                    Toast.LENGTH_SHORT).show();
        } else if (KeyEvent.KEYCODE_BACK == keyCode) {
            dialog();

        }
        return super.onKeyDown(keyCode, event); // 不会回到 home 页面
    }

    protected void dialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setMessage("确认退出吗？");
        builder.setTitle("提示");
        builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                MainActivity.this.finish();
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.create().show();
    }
}
